package se.jayway.opengl.tutorial.mesh;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class MyButton extends Mesh2D {
	public float u1, v1;
	public float u2, v2;
	int bufferIndex;
	int numSprites;

	public MyButton() {
		super();
		this.u1 = 0;
		this.v1 = 0;
		this.u2 = 0.5f;
		this.v2 = 0.5f;
		this.bufferIndex = 0;
		this.numSprites = 0;
		int maxVertices = 4;
		int maxIndices = 6;
		boolean hasColor = false;
		boolean hasTexCoords = true;

		this.hasColor = hasColor;
		this.hasTexCoords = hasTexCoords;
		this.vertexSize = (2 + (hasColor ? 4 : 0) + (hasTexCoords ? 2 : 0)) * 4;
		this.tmpBuffer = new int[maxVertices * vertexSize / 4];

		ByteBuffer buffer = ByteBuffer.allocateDirect(maxVertices * vertexSize);
		buffer.order(ByteOrder.nativeOrder());
		vertices = buffer.asIntBuffer();

		if (maxIndices > 0) {
			buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8);
			buffer.order(ByteOrder.nativeOrder());
			indices = buffer.asShortBuffer();
		} else {
			indices = null;
		}

		short[] indices = new short[6];
		int len = indices.length;
		short j = 0;
		for (int i = 0; i < len; i += 6, j += 4) {
			indices[i + 0] = (short) (j + 0);
			indices[i + 1] = (short) (j + 1);
			indices[i + 2] = (short) (j + 2);
			indices[i + 3] = (short) (j + 2);
			indices[i + 4] = (short) (j + 3);
			indices[i + 5] = (short) (j + 0);
		}
		float[] verticesBuffer = { 0, 0, u1, v2, 64, 0, u2, v2, 64, 64, u2, v1,
				0, 64, u1, v1 };
		setVertices(verticesBuffer);
		setIndices(indices);

	}

}
